######################
#
# Settings
#
######################

CXX = g++
CXXFLAGS = -g -Wall
LIBS = -lm

TESTS =  DocumentVector-test HTMLDocument-test Index-test Dictionary-test 
PROGRAMS = Kmeans

######################
#
# Dependencies
#
######################

Kmeans.o: Kmeans.cpp Kmeans.h DocumentVector.o Index.o Cluster.h 

Dictionary.o: Dictionary.cpp Dictionary.h
Dictionary-test.o: Dictionary.cpp Dictionary.h

DocumentVector.o: DocumentVector.cpp DocumentVector.h
DocumentVector-test.o: DocumentVector.cpp DocumentVector.h

HTMLDocument.o: HTMLDocument.cpp HTMLDocument.h
HTMLDocument-test.o: HTMLDocument.cpp HTMLDocument.h

Index.o: Index.cpp Index.h Dictionary.o DocumentVector.o HTMLDocument.o stringtok.h
Index-test.o: Index.cpp Dictionary.o DocumentVector.o HTMLDocument.o stringtok.h

#######################
#
# Rules, do not touch
#
#######################

all: $(PROGRAMS)

clean:
	rm -f $(PROGRAMS) *.o $(TESTS)

%: %.o
	$(CXX) $(LIBS) $^ -o $@
		
%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

%-test.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@ -DTEST

	
all-tests: $(TESTS)

test: all-tests
	@for i in $(TESTS); do echo Running $$i; ./$$i || exit 1; done
